package model.displayer;

import javafx.scene.paint.Color;
import model.Point;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class ShapeDisplayerComposite implements ShapeDisplayer
{
    Set<ShapeDisplayer> children;
    ShapeDisplayer father;

    public ShapeDisplayerComposite()
    {
        this.children = new HashSet<>();
        this.father = null;
    }

    @Override
    public Color getColor()
    {
        return ShapeDisplayerJFxImpl.DEFAULT_STROKE;
    }

    @Override
    public void setLocation(Point start, Point end){}

    @Override
    public void expand(double multi)
    {
        for(ShapeDisplayer child: children )
            child.expand(multi);
    }

    @Override
    public void shrink(double multi)
    {
        for(ShapeDisplayer child: children )
            child.shrink(multi);
    }

    @Override
    public void move(double x,double y)
    {
        for(ShapeDisplayer child: children )
            child.move(x,y);
    }

    @Override
    public void setOutStanding(boolean isOutStanding)
    {
        for(ShapeDisplayer child: children )
            child.setOutStanding(isOutStanding);
    }

    @Override
    public void setColor(Color color)
    {
        for(ShapeDisplayer sd:children)
            sd.setColor(color);
    }

    @Override
    public void setSelected(boolean isSelected)
    {
        for(ShapeDisplayer sd:children)
            sd.setSelected(isSelected);
    }

    @Override
    public void show()
    {
        for(ShapeDisplayer sd:children)
            sd.show();
    }

    @Override
    public void clear()
    {
        for(ShapeDisplayer sd:children)
            sd.clear();
    }

    @Override
    public void addChild(ShapeDisplayer child)
    {
        if(!children.contains(child))
            children.add(child);
    }

    @Override
    public void removeChild(ShapeDisplayer child)
    {
        if(children.contains(child))
            children.remove(child);
    }

    @Override
    public void setFather(ShapeDisplayer father){this.father = father;}

    @Override
    public ShapeDisplayer getFather(){return this.father;}

    @Override
    public Iterator<ShapeDisplayer> iterator() { return children.iterator(); }

    @Override
    public ShapeDisplayer clone()
    {
        ShapeDisplayerComposite copy = new ShapeDisplayerComposite();
        for(ShapeDisplayer child: children )
        {
            ShapeDisplayer childCopy = child.clone();
            copy.addChild(childCopy);
            childCopy.setFather(copy);
        }
        return copy;
    }
}
